package com.eccg.shopping.activity;

import java.util.ArrayList;

import com.eccg.shopping.R;
import com.eccg.shopping.entity.FloorInfo;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class FloorListActivity extends BaseActivity {
	
	private ListView floorListView;
	private ArrayList<FloorInfo> floorInfoList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.floor_list);
		floorListView = (ListView) findViewById(R.floorList.floorlistView);
		getInfoList();
		FloorAdapter adapter = new FloorAdapter();
		floorListView.setAdapter(adapter);
		floorListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				FloorInfo info = (FloorInfo) parent.getItemAtPosition(position);
				Intent intent = new Intent();
				intent.putExtra("floorNum", info.getFloorNum());
				intent.setClass(FloorListActivity.this, SingleCengActivity.class);
				startActivity(intent);
				finish();
			}
			
		});
	}
	
	@Override
	protected void initHeader() {
		// TODO Auto-generated method stub
		super.initHeader();
		titleTx.setText("楼层选择");
		Button backBtn = new Button(this);
		backBtn.setText("返回");
		backBtn.setGravity(Gravity.CENTER);
		backBtn.setTextSize(16);
		backBtn.setTextColor(getResources().getColor(R.color.white));
		backBtn.setBackgroundResource(R.drawable.left_btn_bg);
		backBtn.setOnClickListener(new Button.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		leftTitle.removeAllViews();
		leftTitle.addView(backBtn);
	}
	
	private void getInfoList(){
		floorInfoList = new ArrayList<FloorInfo>();
		FloorInfo info1 = new FloorInfo();
		info1.setFloorNum("1F");
		info1.setCategory("珠宝首饰");
		info1.setCategoryInfo("老庙黄金\\周大福\\ENZO\\...");
		FloorInfo info2 = new FloorInfo();
		info2.setFloorNum("2F");
		info2.setCategory("精品服饰");
		info2.setCategoryInfo("老庙黄金\\周大福\\ENZO\\...");
		FloorInfo info3 = new FloorInfo();
		info3.setFloorNum("3F");
		info3.setCategory("礼品箱包");
		info3.setCategoryInfo("老庙黄金\\周大福\\ENZO\\...");
		FloorInfo info4 = new FloorInfo();
		info4.setFloorNum("4F");
		info4.setCategory("家具橱柜");
		info4.setCategoryInfo("老庙黄金\\周大福\\ENZO\\...");
		FloorInfo info5 = new FloorInfo();
		info5.setFloorNum("5F");
		info5.setCategory("珠宝首饰");
		info5.setCategoryInfo("老庙黄金\\周大福\\ENZO\\...");
		FloorInfo info6 = new FloorInfo();
		info6.setFloorNum("6F");
		info6.setCategory("珠宝首饰");
		info6.setCategoryInfo("老庙黄金\\周大福\\ENZO\\...");
		floorInfoList.add(info1);
		floorInfoList.add(info2);
		floorInfoList.add(info3);
		floorInfoList.add(info4);
		floorInfoList.add(info5);
		floorInfoList.add(info6);
	}
	
	
	class FloorAdapter extends BaseAdapter{

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return floorInfoList.size();
		}

		@Override
		public FloorInfo getItem(int position) {
			// TODO Auto-generated method stub
			return floorInfoList.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			FloorInfo info = getItem(position);
			ViewHolder holder = null;
			if(convertView == null){
				LayoutInflater inflater = getLayoutInflater();
				convertView = inflater.inflate(R.layout.floor_list_item, null);
				TextView floorNumTx = (TextView) convertView.findViewById(R.floorList.floorNumTx);
				TextView categoryTx = (TextView) convertView.findViewById(R.floorList.categoryTx);
				TextView categoryInfoTx = (TextView) convertView.findViewById(R.floorList.categoryInfoTx);
				holder = new ViewHolder();
				holder.floorNumTx = floorNumTx;
				holder.categoryTx = categoryTx;
				holder.categoryInfoTx = categoryInfoTx;
				convertView.setTag(holder);
			}
			
			holder = (ViewHolder) convertView.getTag();
			holder.floorNumTx.setText(info.getFloorNum());
			holder.categoryTx.setText(info.getCategory());
			holder.categoryInfoTx.setText(info.getCategoryInfo());
			
			return convertView;
		}
		
		class ViewHolder{
			TextView floorNumTx;
			TextView categoryTx;
			TextView categoryInfoTx;
		}
		
	}
	
	@Override
	protected int getMenuIndex() {
		// TODO Auto-generated method stub
		return 0;
	}

}
